<?php
		require_once('inc/config.php');
		
		function is_room_name_valid($aName){
			if (strlen($aName) > 13 && strlen($aName) < 16){
				$pattern = '/^([a-z0-9])+$/';
				if (preg_match($pattern, $aName)){
					return true;
				}else{
					return false;
				}
			}
		}
		
		function check_room($room_url){
			try {
				$pdo_data = DB_TYPE.":host=".DB_HOST.";dbname=".DB_NAME;
				$pdo = new PDO($pdo_data, DB_USER, DB_PASS);
				$sql = $pdo->prepare("SELECT id FROM ".DB_TABL." WHERE room_url LIKE '".$room_url."'");
				$sql->execute();
				$data = $sql->fetchAll(PDO::FETCH_ASSOC);
				if($data){
					$room_id = $data[0]['id'];
					echo print_room($room_id);
				}else{
					echo "no chatrooms here.";
				}
				$sql = null;
			}
			catch(PDOException $e){
			    echo $e->getMessage();
			}
		}
		
		function print_room($room_id){
			$r = '<div id="chatWrapper">';
			$r.= print_room_content($room_id);
			$r.= '</div>';
			return $r;
		}
		
		function print_room_content($room_id){
			$r = '<h2>Welcome to the chat room id '.$room_id.'</h2>';
			$r.= '<div id="leftChatArea">';
			$r.= '<textarea></textarea><input type="text" value="type your text here.."/><input type="submit" value="submit"/>';
			$r.= '</div>';
			$r.= '<div id="rightChatArea">';
			$r.= '
					<ul>
						<li><a href="#">user 1</a></li>
						<li><a href="#">user 2</a></li>
						<li><a href="#">user 3</a></li>
						<li><a href="#">user 4</a></li>
						<li><a href="#">user 5</a></li>
					</ul>
				';
			$r.= '</div>';
			return $r;
		}
		
?>